/**
 * 
 */
package org.dragonfire.dasm.directives;

import java.util.ArrayList;

import org.dragonfire.dasm.Command;
import org.dragonfire.dasm.CompileException;
import org.dragonfire.dasm.Listing;
import org.dragonfire.dasm.DirectiveManager.Directive;

/**
 * Loads a {@link org.dragonfire.dasm.DirectiveManager.Directive} from a custom
 * or user location and prepares it for use in all following lines of code.<br />
 * <br />
 * Format:<br />
 * <code>#LOADDIRECTIVE <i>&lt;className&gt;</i></code><br />
 * <br />
 * Parameters:<br />
 * <table>
 * <tr>
 * <td><code>className</code></td>
 * <td>(String) The fully-qualified name of the class to load. This class must
 * already be on java's classpath and be compiled without errors.</td>
 * </tr>
 * </table><br />
 * Errors:<br />
 * <table>
 * <tr>
 * <td> <code>ERROR_UNABLE_TO_LOAD_DIRECTIVE</code></td>
 * <td>Thrown if the directive class could not be found, not a subclass
 * {@link org.dragonfire.dasm.DirectiveManager.Directive}, or threw an
 * exception in it's constrctor</td>
 * </tr>
 * </table>
 * 
 * @author Darth Android
 * @version 2.0
 * @see org.dragonfire.dasm.DirectiveManager#loadDirective(String)
 * @see org.dragonfire.dasm.DirectiveManager.Directive
 */
public class Loaddirective extends Directive {

	/**
	 * {@inheritDoc}
	 */
	@Override
	public ArrayList<Listing> pass1(Command c) {
		try {
			getDM().loadDirective(evalString(c.getParam(0)));
		} catch (Exception e) {
			throw new CompileException("ERROR_UNABLE_TO_LOAD_DIRECTIVE", evalString(c.getParam(0)), e.getMessage());
		}
		return null;
	}
}
